package com.gym;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.yaml.snakeyaml.Yaml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

@SpringBootApplication
public class BackendApplication {

    private static final Logger log = LoggerFactory.getLogger(BackendApplication.class);

    public static void main(String[] args) {
        // 在启动前手动加载并验证 YAML 文件
        try {
            Resource resource = new ClassPathResource("application.yml");
            InputStream inputStream = resource.getInputStream();
            Yaml yaml = new Yaml();
            Object data = yaml.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
            System.out.println("YAML 文件加载成功：" + data);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("YAML 文件加载失败，请检查文件编码和内容！");
            return;
        }

        SpringApplication.run(BackendApplication.class, args);
        log.info("=====================项目后端启动成功============================");
    }
}
